const app = getApp();
const https = require('../../utils/https');
var WxParse = require('../../wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkItems: [],
    order_id: null,
    inspection_id: null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options.inspector_id)
    if (options && options.order_id != '') {
      that.setData({
        order_id: options.order_id,
        inspector_id: options.inspector_id
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getCheckResult()
  },
  /* 获取验房项目
 * @param orderId 订单id
     */
  getCheckResult() {
    const {order_id, inspector_id} = this.data
    wx.request({
      url: 'https://wx.amagich.com/' + 'v1/' + 'getCheckResultV02',
      data: {
        inspector_id,
        order_id,
      },
      header: {
        "Content-Type": "application/json"
      },
      method: 'GET',
      success: res => {
        console.log(res.data.resultData)
        const checkItems = res.data.resultData;
        checkItems[0].expend = true
        this.setData({
          checkItems
        })
      }})
  },
  expendItem(e) {
    const index = e.currentTarget.dataset.index;
    const checkItems = JSON.parse(JSON.stringify(this.data.checkItems))
    checkItems[index].expend = !checkItems[index].expend
    this.setData({
      checkItems
    })
  },
  /**
   * @xk 获取生成报告的相关信息
   * @param {} res
   */
  getReportInfo: function(res){
    var that = this,
        order_sn = this.data.order_sn;
    https.post('getReportInfo',{order_sn: order_sn},true,'加载中').then(res=>{
      that.setData({
        report_txt_num: res.reportTextNum,
        check_time: res.check_time,
        inspector_name: res.inspector_name,
        house_register: res.house_register,
        check_end_time: res.check_end_time,
        position_list: res.position_list,
        check_by: res.check_by,
        app_name: res.app_name,
        tel: res.tel,
        app_ewm: res.app_ewm,
        kh: res.kh
      })
    })
  },

  /**
   * @xk 生成验房报告
   */
  createReport: function(){
    var that = this,
        order_sn = this.data.order_sn;
    that.setData({
      loading: true,
      disabled: true
    })
    https.post('createReport',{order_sn: order_sn},false,'正在生成报告').then(res=>{
      setTimeout(() => {
        wx.navigateTo({
          url: '/pages/inspection_viewreport/viewreport?order_sn='+order_sn,
        })
      }, 1500);
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.onShow();
  },
})
